module.exports = app => {
  
    app.passport.verify(async (ctx, user) => {

      ctx.logger.info(user, '2222222222222')

      // 检查用户
      // assert(user.provider, 'user.provider should exists');
      // assert(user.playload, 'user.playload should exists');

      const { username } = user.payload

      const existsUser = await ctx.service.user.findByUsername( 
          username, 
          { 
            attributes: { exclude: ['userpwd'] }, 
            include: {
              model: app.model.TCompanycnfo,
              as: 'company',
              attributes: [ 'Co_ID', 'Co_Name', 'Co_Logo_Text', 'Co_Logo' ]
            } 
          } 
        );

      if (!existsUser) {
        ctx.throw(422, '用户错误!')
      }

      return existsUser;
    });
  
    // 将用户信息序列化后存进 session 里面，一般需要精简，只保存个别字段
    app.passport.serializeUser(async (ctx, user) => {
    // 处理 user
    // ...
       //return user;
    });
  
    // 反序列化后把用户信息从 session 中取出来，反查数据库拿到完整信息
    app.passport.deserializeUser(async (ctx, user) => {
    // 处理 user
    // ...
       //return user;
    });
  };